<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        #container {
            width: 750px;
            height: 291px;
            margin: 100px auto;
            background: #ccc;
            overflow: hidden;
            position: relative;
        }

        #indicators {
            position: absolute;
            right: 20px;
            bottom: 20px;
            z-index: 1;
        }

        #indicators li {
            float: left;
            width: 20px;
            height: 20px;
            margin-right: 10px;
            background: #000;
            color: #fff;
            text-align: center;
            line-height: 20px;
            cursor: pointer;
        }

        #indicators li.active {
            background: #f00;
        }

        #imgs {
            position: absolute;
            left: 0;
            top: 0;
            transition: left 1.5s;
        }

        #imgs img {
            float: left;
        }

        #arrows span {
            width: 40px;
            height: 40px;
            background: rgba(0, 0, 0, 0.8);
            color: #fff;
            text-align: center;
            line-height: 40px;
            position: absolute;
            top: 50%;
            margin-top: -20px;
            cursor: pointer;
            user-select: none;
        }

        #prev {
            left: 0;
        }

        #next {
            right: 0;
        }

        /* 圆形滚动 */
        #div {
            display: flex;
            position: relative;
            top: -90px;
            justify-content: center;
        }

        .box {
            width: 15px;
            height: 15px;
            border: 1px solid #0e0e0e;
            margin-right: 10px;
            border-radius: 10px;
            transition: 0.3s;
        }

        #div .active {
            background-color: rgb(15, 240, 4);
        }

        /* end */
    </style>

</head>

<body>
    <div id="container">
        <ul id="indicators">
            <li class="active" index="0">1</li>
            <li index="1">2</li>
            <li index="2">3</li>
            <li index="3">4</li>
            <li index="4">5</li>
        </ul>
        <div id="imgs">
            <img src="imgs/1.jpg" alt="">
            <img src="imgs/2.jpg" alt="">
            <img src="imgs/3.jpg" alt="">
            <img src="imgs/4.jpg" alt="">
            <img src="imgs/5.jpg" alt="">
        </div>
        <div id="arrows">
            <span id="prev">&lt;</span>
            <span id="next">&gt;</span>
        </div>
    </div>

    <!-- 圆形滚动 -->
    <div id="div">
        <div class="box active"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>

    </div>
    <!-- end -->

    <script>
        let container = document.querySelector('#container');
        let indicatorsUl = document.querySelector('#indicators');
        let indicators = indicatorsUl.children;//indicatorsUl.querySelectorAll('li');
        let imgs = document.querySelectorAll('#imgs img');
        let imgBox = document.querySelector('#imgs');
        let prev = document.querySelector('#prev');
        let next = document.querySelector('#next');
        let currIndex = 0;
        // 滚动
        let div = document.querySelectorAll('#div .box')
       let a = div.length
       console.log(a);
        let times = 0
       function btn(){
        next.addEventListener('click', function () {
            times++
            for (let i = 0; i < div.length; i++) {
                if (times < div.length) {
                    div[i].classList.remove('active')
                    div[times].className = 'box active'
                } else {
                    times = 0
                }
            }
        })
       }
       btn()
        // end

        imgBox.style.width = imgs.length * container.offsetWidth + 'px'
       console.log(imgBox.style.width );
        indicatorsUl.addEventListener('click', e => {
            let target = e.target
            if (target.tagName === 'LI') {
                let index = target.getAttribute('index')
                currIndex = index
                changeImg(index)
            }
        }, false)


        next.addEventListener('click', function (e) {
            if (this == next) {
                currIndex++
                if (currIndex == imgs.length) {
                    currIndex = 0
                }
            }
            changeImg(currIndex)
            // console.log(111);
        })

        prev.addEventListener('click', function (e) {
            currIndex--
            if (currIndex < 0) {
                currIndex = imgs.length - 1
            }
            changeImg(currIndex)
        })

        function changeImg(index) {
            for (let i = 0; i < indicators.length; i++) {
                indicators[i].className = ''
            }
            indicators[index].className = 'active'

            imgBox.style.left = -container.offsetWidth * currIndex + 'px'
        }

        let timer
        function go() {
            timer = setInterval(() => {
                next.click()
            }, 3000);
        }
        // go();

        container.addEventListener('mouseover', () => {
            clearInterval(timer);
        }, false);
        container.addEventListener('mouseout', () => {
            // go();
        }, false);


    </script>
</body>

</html>